<?php 
/* SVN FILE: $Id$ */
/* StoreController Test cases generated on: 2009-10-26 16:13:44 : 1256541224*/
App::import('Controller', 'Store');
require_once "Benchmark/Timer.php";

class StoreTestController extends StoreController {
	var $autoRender = false;
	#var $uses = array('Order','Product');
	function redirect($url=NULL,$code=NULL) { 
		$this->lastRedirectUrl = $url; 
		$action = $this->params['action'];
		#debug("$action action redirects to $url");
		$this->Session->write('test.lastRedirectUrl',$url);
		return true;
	}
}
class StoreControllerRerfTest extends CakeTestCase {
	var $Store = null;
	# fixtureつかったり、テーブルからコピーしたりと挙動がよくわからん。fixtureつかうように統一するか？
	var $fixtures = array('app.order_performance');
	function startTest() {
		$this->Store = new StoreTestController();
		$this->Store->constructClasses();
		
		$this->Order =& ClassRegistry::init('Order');
		#$this->Order->deleteAll('Order.id > 0');
		
		$this->timer = new Benchmark_Timer;		
	}

	function testSaveBulkOrders(){	
		$results = array();
		$this->Order->recursive = -1;
		$results = $this->Order->find('all');
		#debug($results);
		$this->timer->start();
		foreach($results as $order){
			$result = $this->testAction('/depot/store/save_order', array(
    			'data' => $order,
    			'fixturize' => false,
    			'method' => 'post',
    			'redirect' => 'false')
			);
			$this->assertEqual($this->Store->Session->read('test.lastRedirectUrl'),'/store/');
			$flash = $this->Store->Session->read('Message.flash');
			$this->assertEqual($flash['message'],'ご注文ありがとうございました');
		}
		$this->timer->stop();
		$profile = $this->timer->getProfiling();
		$total = $profile[1]['total'];
		debug("トータル: $total 秒");
	}

	function endTest() {
		unset($this->Store);
	}
	function tearDown(){
		unset($this->Store);
	}
}
?>